withRetriesOrThrow

suspend fun <T> suspend () -> T.withRetriesOrThrow(until: (ErrorOr<T>) -> Boolean = { it.isRight() }, additionalTimes: Int = 4, delay: Duration = Duration.ofMillis(20L), exponentialBackoff: Boolean = false, jitter: Boolean = false): ErrorOr<T>(source)

Retry a suspended supplier until a maximum number of times or a predicate has been fulfilled.

Parameters

until

the predicate that indicates success. Defaults to "no exceptions encountered".

additionalTimes

how many times to retry before giving up. Defaults to 4 (5 attempts in total).

delay

how long to delay between attempts. Defaults to 20ms.

exponentialBackoff

if true, will double the delay on each attempt. Defaults to false.

jitter

if true, will stagger the attempts to reduce likelihood of collisions. Defaults to false.